<?php
/**
 * Link Class API
 *
 * @package OWL
 * @subpackage Core
 * @author KeiMOon
 * @since 1.5
 */

 class Owl_Link {

    /**
     * Guess site url
     *
     * @return string Site url
     */
    static function guess_site_url() {
        $path_array = explode("/", $_SERVER["PHP_SELF"]);
        if (in_array(end($path_array), array("index.php", "load-scripts.php", "load-styles.php"))) {
            return implode("/", array_slice($path_array, 0, -1)) . "/";
        }
        elseif (strpos($_SERVER["PHP_SELF"], 'ckeditor')) {
            return implode("/", array_slice($path_array, 0, -6)) . "/";
        }
        else {
            return implode("/", array_slice($path_array, 0, -2)) . "/";
        }
    }


     /**
     * Home URL
     */
    static function site_url($echo = true) {
        if ($echo)
            echo SITE_URL;
        else
            return SITE_URL;
    }

    /**
     * Upload URL
     */
    static function upload_url($echo = true) {
        if ($echo)
            echo self::site_url(false).UPLOAD_DIR."/";
        else
            return self::site_url(false).UPLOAD_DIR."/";

    }

    /**
     * Upload URL
     */
    static function ajax_url($echo = true) {
        if ($echo)
            echo self::site_url(false).AJAX_DIR."/";
        else
            return self::site_url(false).AJAX_DIR."/";

    }

    /**
     * Image Url
     */

     static function image_url($echo = true) {
         if ($echo)
            echo self::site_url(false).IMAGE_DIR."/";
         else
            return self::site_url(false).IMAGE_DIR."/";
     }

     /**
      * Style URL
      */
     static function default_style_url($echo = true) {
         if ($echo)
            echo self::site_url(false).STYLE_DIR."/";
         else
            return self::site_url(false).STYLE_DIR."/";
     }

     /**
      * Style URL
      */
     static function default_script_url($echo = true) {
         if ($echo)
            echo self::site_url(false).SCRIPT_DIR."/";
         else
            return self::site_url(false).SCRIPT_DIR."/";
     }

     /**
      * Theme URL
      */
     static function theme_url($echo = true) {
         if ($echo)
            echo self::site_url(false).THEME_DIR."/";
         else
            return self::site_url(false).THEME_DIR."/";
     }

     /**
      * Current theme URL
      */
     static function current_theme_url($echo = true) {
         if ($echo)
            echo self::site_url(false).THEME_DIR."/".Owl_Theme_Control::get_current_theme()."/";
         else
            return self::site_url(false).THEME_DIR."/".Owl_Theme_Control::get_current_theme()."/";
     }

     /**
      * Template URL
      */
     static function template_url($template = "home", $echo = true, $array_var = false) {
         $uri = "index.php?template=" . $template;
         if ($array_var) {
             $uri = Owl_Functions::add_query_arg($array_var, $uri);
         }
         if ($echo)
            echo self::site_url(false).apply_rewrite_rules($uri);
         else
            return self::site_url(false).apply_rewrite_rules($uri);
     }

     /**
      * Page URL
      */
     static function page_url($page_name, $echo = true) {
         if ($echo)
            echo self::site_url(false).apply_rewrite_rules("index.php?template=page&var=" . $page_name);
         else
            return self::site_url(false).apply_rewrite_rules("index.php?template=page&var=" . $page_name);
     }

     /**
      * Help URL
      */
     static function help_url($echo = true) {
         if ($echo)
            echo self::site_url(false).HELP_DIR."/";
         else
            return self::site_url(false).HELP_DIR."/";
     }
}

